package com.project.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.project.dao.BorrowReturnInfoDAO;
import com.project.dao.GenericDAO;
import com.project.dto.BorrowBookRank;
import com.project.dto.ReaderBorrowRank;
import com.project.entity.BorrowReturnInfo;
import com.project.service.BorrowReturnInfoService;

@Service("borrowReturnInfoService")
public class BorrowReturnInfoServiceImpl extends
		GenericServiceImpl<BorrowReturnInfo, Integer> implements
		BorrowReturnInfoService {
	private BorrowReturnInfoDAO borrowreturnDAO;

	@Override
	public void saveOrUpdate(BorrowReturnInfo borrowReturnInfo) {
		if (borrowReturnInfo.getId() == null) {
			save(borrowReturnInfo);
		} else if (get(borrowReturnInfo.getId()) == null) {
			save(borrowReturnInfo);
		} else {
			update(borrowReturnInfo);
		}
	}

	@Resource(name = "borrowReturnInfoDAO")
	@Override
	public void setGenericDAO(
			GenericDAO<BorrowReturnInfo, Integer> borrowReturnInfoDAO) {
		this.genericDAO = borrowReturnInfoDAO;
		this.borrowreturnDAO = (BorrowReturnInfoDAO) borrowReturnInfoDAO;

	}

	// 分页
	@Override
	public List<BorrowReturnInfo> getBorrowList(String bookName,
			String readerName, int pageSize, int pageNow, String... checks) {
		return borrowreturnDAO.getBorrowList(bookName, readerName, pageSize,
				pageNow, checks);
	}

	// 分页总记录数
	@Override
	public Integer borrowedCount(String bookName, String readerName,
			String... checks) {
		return borrowreturnDAO.borrowedCount(bookName, readerName, checks);
	}

	@Override
	public BorrowReturnInfo get(String bookname, String readername) {
		return borrowreturnDAO.get(bookname, readername);
	}

	@Override
	public List<BorrowBookRank> borrowBookRank() {
		return borrowreturnDAO.borrowBookRank();
	}

	@Override
	public List<ReaderBorrowRank> readerBorrowRank() {
		return borrowreturnDAO.readerBorrowRank();
	}

	@Override
	public List<BorrowReturnInfo> get(String readerName) {
		return borrowreturnDAO.get(readerName);

	}

	@Override
	public Integer borrowedAmount(String readerName) {
		return borrowreturnDAO.borrowedAmount(readerName);
	}

}
